<?php 
namespace app\common\model;
class MemberToken extends Common{
	public function create_token($userid,$username){
		$data = ['username'=>$username,'userid'=>$userid,'token'=>md5(create_randomstr(10)),'addtime'=>SYS_TIME];
		$this->save($data);
		return $data['token'];
	}
	public function delete_token($token){
		return $this->where("token",$token)->delete();
	}
	public function check_token($token,$time){
		$addtime = $this->where("token",$token)->value("addtime");
		trace($time - $addtime);
		if($time - $addtime > 24 * 3600){  //如果当前时间减去添加时的时间大约1天
			return false;
		}
		$userid = $this->where("token",$token)->value("userid");
		return model("AdminUser")->get_data(['item_id'=>$userid]);
	}
}